#include "Menustate.h"
#include "Game.h"

MenuState::MenuState(Resources* res)
:State(res)
{
	_current_state = _next_state = ST_Menu;
	_select = _resources->Select;

	x = SELECT_X;
	y = SELECT_Y;
	_choose = 1;
}

MenuState::~MenuState(void)
{
	
}

void MenuState::Update(float time)
{

}

void MenuState::ProcessInput(Input* input)
{
	int key = input->OnKeyDown();

	if (key == DIK_UP)
	{
		if (_onSound)
			_resources->_audio->PlaySoundA(_resources->Selected);

		if (_choose <= 1)
		{
			x = 520;
			y = 490;
			_choose = 5;
		}
		else
		{
			x -= 15;
			y -= 60;
			_choose--;
		}
	}
	else if (key == DIK_DOWN)
	{
		if (_onSound)
			_resources->_audio->PlaySoundA(_resources->Selected);

		if (_choose >= 5)
		{
			x = SELECT_X;
			y = SELECT_Y;
			_choose = 1;
		}
		else
		{
			x += 15;
			y += 60;
			_choose++;
		}
	}
	else if (key == DIK_RETURN)
	{
		switch (_choose)
		{
		case 1: // play
			_next_state = ST_Play;
			_close = true;
			break;
		case 2: // continues
			_next_state = ST_Continues;
			_close = true;
			break;
		case 3:	// option
			_next_state = ST_Option;
			_close = true;
			break;
		case 4: // about
			_next_state = ST_About;
			_close = true;
			break;
		case 5: // exit
			_next_state = ST_Exit;
			_close = true;
			break;
		default:
			break;
		}
	}
	
}

void MenuState::Render(LPD3DXSPRITE spriteHandler)
{
	_resources->_pd3ddv->StretchRect(_resources->_bgMenu->GetImage(), NULL, _resources->_back_buffer, NULL, D3DTEXF_NONE);
	
	D3DXVECTOR3 positionRender(x, y, 0);
	spriteHandler->Draw(_select->GetImage(), NULL, NULL, &positionRender, D3DCOLOR_XRGB(255, 255, 255));
}

void MenuState::Release()
{
	
}